import type { IColumnsOption } from 'vc';
import { INDEX, COMPANY_NAME, INFO_SOURCE, PROVINCE, CITY, COUNTRY, INDUSTRY_CATEGORY, BUSINESS_DATA, REGISTERED_CAPITAL, CellRenderMap } from '@/utils';

export function useTable() {
  const columns = ref<IColumnsOption[]>([
    { ...INDEX },
    { ...COMPANY_NAME },
    {
      title: '资质类别',
      field: 'contractingLv',
      width: 210,
      align: 'center',
      sortable: true
    },
    {
      title: '资质证书号',
      field: 'certificateNumber',
      width: 120,
      align: 'center',
      sortable: true,
      cellRender:{ name: CellRenderMap.HighLight }
    },

    {
      title: '发证日期',
      field: 'periodOfValidityStartDate1',
      width: 150,
      align: 'center',
      sortable: true,
      formatter({ row }) {
        return row.periodOfValidityStartDate ?? (row.noticeDate || '-');
      }
    },
    {
      title: '有效起止日期',
      width: 250,
      field: 'periodOfValidityStartDate2',
      align: 'center',
      sortable: true,
      slots: {
        default({ row }) {
          const showText = row.isExpired !== null ? (row.isExpired ? '过期' : '有效') : '';
          const className = 'revocation ' + 'revocation-' + row.isExpired;
          const stDate = row.periodOfValidityStartDate ?? row.noticeDate;
          const isEmpty = stDate || row.periodOfValidityExpirationDate;

          return (
            <span>
              {isEmpty ? <span>
                {stDate || '-'} 至 {row.periodOfValidityExpirationDate || '-'}
              </span> : '-'}
              {showText ? <span title={showText} class={className}>
                {showText}
              </span> : ''}
            </span>
          );
        }
      }
    },
    {
      title: '发证机关',
      field: 'issuingDepartment',
      width: 220,
      align: 'center',
      sortable: true
    },
    {
      ...INFO_SOURCE('dataSource'),
      width: 200
    },
    { ...PROVINCE },
    { ...CITY },
    { ...COUNTRY },
    { ...INDUSTRY_CATEGORY },
    { ...BUSINESS_DATA },
    { ...REGISTERED_CAPITAL }
  ]);

  return {
    columns
  };
}
